home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / misc / emu / NESDevTools.lha / Raw2CHR / Raw2CHR.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-17  |  1.5 KB  |  79 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc,char *argv[])
  5. {
  6.     
  7.     short int tempchar;
  8.     short int plane0[8][32];
  9.     short int plane1[8][32];
  10.     int width,i,column,row,plane;
  11.     FILE *FI,*FO;
  12.     
  13.     fprintf(stderr,"\nCharacter ROM Creator (C)1999 Chris Covell (ccovell@direct.ca)\n\n");
  14.  
  15.   if((argc!=3) && (argc!=4))
  16.   {
  17.     fprintf(stderr,"Usage: %s infile outfile [-w]\n\n",argv[0]);
  18.     return(1);
  19.   }
  20.  
  21.   if(!(FI=argc<2? stdin:fopen(argv[1],"rb")))
  22.   { fprintf(stderr,"%s: Can't open input file\n\n",argv[0]);return(1); }
  23.   if(!(FO=argc<2? stdout:fopen(argv[2],"wb")))
  24.   { fprintf(stderr,"%s: Can't open output file\n\n",argv[0]);return(1); }
  25.   
  26.   plane=0;
  27.   column=0;
  28.   row=0;  
  29.   
  30.   if(argc==4 && (!strncmp(argv[3],"-w",2))) width=32;
  31.   else width=16;
  32.  
  33.   while((tempchar=fgetc(FI))>=0)
  34.   {
  35.     if(plane)
  36.     plane1[row][column]=tempchar;
  37.     else
  38.     plane0[row][column]=tempchar;
  39.     
  40.     column=column+1;
  41.     
  42.     if(column>=width)
  43.     {
  44.         column=0;
  45.         plane=plane+1;
  46.     }
  47.     
  48.     if(plane>=2)
  49.     {
  50.         plane=0;
  51.         row=row+1;
  52.     }
  53.     
  54.     if(row>=8)
  55.     {
  56.         
  57.         for(column=0; column<width; column=column+1)
  58.         {
  59.             for(row=0; row<8; row=row+1)
  60.             {
  61.                 fputc(plane0[row][column],FO);
  62.             }
  63.             for(row=0; row<8; row=row+1)
  64.             {
  65.                 fputc(plane1[row][column],FO);
  66.             }            
  67.         }
  68.         row=0;
  69.         column=0;
  70.         plane=0;
  71.     }
  72.   }    
  73.   
  74.    
  75.   fclose(FO);
  76.   fclose(FI);
  77.     
  78.   return(0);
  79. }